package com.example.demo.controller;
import com.example.demo.entity.Sys_role;
import com.example.demo.service.Sys_roleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
public class Sys_roleController {
    @Autowired
    private Sys_roleService sys_roleService;
    @GetMapping("/saveSys_role")
    public String saveSysRole(Sys_role sys_role)
    {
        sys_role.setName("普通员工");
        sys_role.setDescription("负责运维");
        sys_role.setCreate_time(20228L);
        sys_role.setCreate_by("小张");
        sys_role.setUpdate_time(202443L);
        sys_role.setUpdate_by("小李");
        sys_role.setDel_flag(1);
        int result=sys_roleService.saveSys_role(sys_role);
        if (result>0){
            return "添加成功";
        }else {
            return "添加失败";
        }
    }
    @GetMapping("/getSys_roleById/{id}")
    public Sys_role getSys_roleById(@PathVariable Integer id){
        return sys_roleService.getSys_roleById(id);
    }
    @GetMapping("/getAllSys_role")
    public List<Sys_role> getAllSys_role(){
        return sys_roleService.getAllSys_role();
    }
    @GetMapping("/deleteSys_role/{id}")
    public String deleteSys_role(@PathVariable Integer id){
        int result=sys_roleService.deleteSys_role(id);
        if(result>0){
            return "删除成功";
        }else {
            return "删除失败";
        }
    }
    @GetMapping("/updateSys_role/{id}")
    public String updateSys_role(@PathVariable Integer id){
        Sys_role sys_role=new Sys_role();
        sys_role.setId(id);
        sys_role.setName("总监");
        sys_role.setDescription("部门的主要管理任务");
        sys_role.setCreate_time(202452L);
        sys_role.setCreate_by("小王");
        sys_role.setUpdate_time(202443L);
        sys_role.setUpdate_by("小李");
        sys_role.setDel_flag(1);
        int result=sys_roleService.updateSys_role(sys_role);
        if(result>0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }
}